package p.ithorns.sample.tracer.otel;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;

import java.nio.charset.StandardCharsets;

/**
 * CustomJsonLayoutEncoder
 *
 * @author HtL
 * @date 2025/3/20 9:22
 * @since 1.0.0
 */
public class CustomJsonLayoutEncoder extends LayoutWrappingEncoder<ILoggingEvent> {
    public CustomJsonLayoutEncoder() {
    }

    public void start() {
        CustomJsonLayout jsonLayout = new CustomJsonLayout();
        jsonLayout.setContext(this.context);
        jsonLayout.setIncludeContextName(false);
        jsonLayout.setAppendLineSeparator(true);
        jsonLayout.setJsonFormatter(new JacksonJsonFormatter());
        jsonLayout.start();
        super.setCharset(StandardCharsets.UTF_8);
        super.setLayout(jsonLayout);
        super.start();
    }
}